package com.kingschan.util.lang;

import java.lang.reflect.Field;

/**
 * ArrayUtil
 * @author kingschan
 *date:2013-07-11
 */
public class ArrayUtil {
	/**
	 * CombinedArray
	 * @param objects
	 * @return
	 */
	public static String[] CombinedArray(String[]...strs){
		String[] str_array ;
		int tortal_length=0;
		for (int i = 0; i < strs.length; i++) {
			tortal_length+=strs[i].length;
		}
		str_array= new String[tortal_length];		
		for (int i = 0; i < strs.length; i++) {
			String[] temp = strs[i];
			int index=0;
			if (i>0) {
				for (int j = 0; j < i; j++) {
					index+=strs[j].length;
				}
			}
			System.arraycopy(temp, 0, str_array, index, temp.length);			
		}		
		return str_array;
		
	}
	/**
	 * CombinedFieldArray
	 * @param strs
	 * @return
	 */
	public static Field[] CombinedFieldArray(Field[]...strs){
		Field[] Field_array ;
		int tortal_length=0;
		for (int i = 0; i < strs.length; i++) {
			tortal_length+=strs[i].length;
		}
		Field_array= new Field[tortal_length];		
		for (int i = 0; i < strs.length; i++) {
			Field[] temp = strs[i];
			int index=0;
			if (i>0) {
				for (int j = 0; j < i; j++) {
					index+=strs[j].length;
				}
			}
			System.arraycopy(temp, 0, Field_array, index, temp.length);			
		}		
		return Field_array;
		
	}
	public static void main(String[] args) {
		String[] str1={"a","b","c"};
		String[] str2={"d","e","f"};
		String[] str3={"g","h","i"};
		String [] s=ArrayUtil.CombinedArray(str1,str2,str3,new String[]{"j","k","l","m"});
		for (String string : s) {
			System.out.println(string);
		}
		 /**
		int elements[ ] = { 1, 2, 3, 4, 5, 6 };
		// ������������
		int hold[ ] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
		// ��elements�����е�����Ԫ�ظ��Ƶ�
		// hold�����У��±��0��ʼ
		System.arraycopy(elements, 0, hold, 0, elements.length);
		for(int i=0;i<elements.length;i++)
		System.out.println("elements["+i+"]="+elements[i]);
		for(int i=0;i<hold.length;i++)
		System.out.println("hold["+i+"]="+hold[i]);
		*/
	}
}
